package com.xiaoyu.merchant.ui.activity.wallet;

import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.EditText;

import com.google.gson.Gson;
import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.PreferencesUtil;
import com.xiaoyu.commonlib.utils.ToastUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.model.MyWalletBean;
import com.xiaoyu.merchant.network.NetworkManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ModificationPayPwdActivity extends BaseActivityWithTitle {

    @BindView(R.id.old_pwd_edit)
    EditText mOldPwd;
    @BindView(R.id.new_pwd_edit)
    EditText mNewPwd;
    @BindView(R.id.confirm_pwd_edit)
    EditText mConfirmPwd;

    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("修改支付密码");
        LayoutInflater.from(this).inflate(R.layout.activity_modification_pay_pwd, parent, true);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.submit_pwd)
    public void submitClick() {
        if (TextUtils.isEmpty(mOldPwd.getText().toString()) || TextUtils.isEmpty(mNewPwd.getText().toString()) || TextUtils.isEmpty(mConfirmPwd.getText().toString())) {
            ToastUtil.showToast(this, "请填写密码");
            return;
        }
        if (!mNewPwd.getText().toString().equals(mConfirmPwd.getText().toString())) {
            ToastUtil.showToast(this, "两次密码不相同");
            return;
        }
        getModificationPayPwd();
    }

    //提交结果
    private void getModificationPayPwd() {
        NetworkManager.modificationPayPwd(PreferencesUtil.getString(PreferencesUtil.TOKEN, ""), mOldPwd.getText().toString(),
                mNewPwd.getText().toString(), mConfirmPwd.getText().toString(), new CommonHttpResponser() {
                    @Override
                    public void onSuccess(String result) {
                        ToastUtil.showToast(ModificationPayPwdActivity.this, "修改支付密码成功");
                        finish();
                    }

                    @Override
                    public void onFailed(String errorCode, String errorDiscription) {
                        if (errorCode.equals("y406")) {
                            ToastUtil.showToast(ModificationPayPwdActivity.this, "原密码错误");
                            return;
                        }
                    }
                });
    }
}
